<?php
/**
 * Created by PhpStorm.
 * User: yanghe
 * Date: 2016/3/22
 * Time: 15:27
**/
namespace Base\Student;

use Illuminate\Support\Facades\DB;
class Student
{
    public static function addTest($student_num,$student_name,$student_age,$student_sex)
    {
        $data["student_num"]=$student_num;
        $data["student_name"]=$student_name;
        $data["student_age"]=$student_age;
        $data["student_sex"]=$student_sex;
        $data["student_department"]=1;
        $data["student_class"]=4;
        $data["student_login"]=3;
        $result=DB::table("student")->insert($data);
        if(null == $result)
        {
            echo "失败";
        }
        else
        {
            dd($data);
        }
    }
    public static function login($login_name,$login_passwd)
    {
        session(["login_name"=>$login_name]);
        $data=DB::table("login")
            ->where("login_name","=",$login_name)
            ->where("login_passwd","=",$login_passwd)
            ->get();
        if(null == $data)
        {
            return false;
        }
        else
        {
            return true;
        }
    }
    public static function _semester()
    {
        $data=DB::table("semester")->get();
        if(null==$data)
        {
            return false;
        }
        else
        {
            return $data;
        }
    }
    public static function _course()
    {
        $data = DB::table("course")->get();
        if (null == $data) {
            return false;
        } else {
            return $data;
        }
    }
    public static function select_id()
    {
        $login_name = session("login_name");
        $student_id = DB::table("student")
            ->join("login", "login_id", "=", "student_login")
            ->where("login_name", "=", $login_name)
            ->pluck("student_id");
        if (null == $student_id) {
            return false;
        } else {
            return $student_id;
        }
    }
        public static function course_id($course_name)
    {
        $course_id=DB::table("course")
            ->where("course_name","=",$course_name)
            ->pluck("course_id");
        if(null == $course_id)
        {
            return false;
        }
        else
        {
            return $course_id;
        }
    }
    public static function semester_id($semester_name)
    {
        $semester_id=DB::table("semester")
            ->where("semester_name","=",$semester_name)
            ->pluck("semester_id");
        if(null == $semester_id)
        {
            return false;
        }
        else
        {
            return $semester_id;
        }
    }
    public static function grade($semester_id,$course_id,$student_id)
    {
        $data=DB::table("grade")
            ->where("semester_grade","=",$semester_id)
            ->where("course_grade","=",$course_id)
            ->where("student_grade","=",$student_id)
            ->pluck("grade_res");
        if(null==$data)
        {
            return false;
        }
        else
        {
            return $data;
        }

    }





}